using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
using WPFExcelReport.Helpers;
using WPFExcelReport.Controls;
namespace WPFExcelReport
{
    public partial class VICC_VKQA
    {
        public DataRow Convert2ICC_VKQA(DataRow dwInput, string ITXDBVERSION, bool IsConvert = false)
        {
            DataSet SResult = new DataSet();
            SResult = QueryICC_VKQA(dwInput, 0);
            DataRow dwReturn = null;
            if (SResult.Tables[0].Rows.Count > 0)
            {
                dwReturn = SResult.Tables[0].Rows[0];
            }
            else
            {
                dwReturn = SResult.Tables[0].NewRow();
            }
            switch (ITXDBVERSION)
            {
                case "YGR":
                    #region=========
         dwReturn["ROWNID"] = " ".PadRight(0 ); 
         dwReturn["MANDANT"] = " ".PadRight(2 ); 
         dwReturn["COLL"] = " ".PadRight(5 ); 
         dwReturn["ART"] = " ".PadRight(24 ); 
         dwReturn["CONS"] = " ".PadRight(70 ); 
         dwReturn["COLOR"] = " ".PadRight(10 ); 
         dwReturn["WID"] = " ".PadRight(10 ); 
         dwReturn["STAFF"] = " ".PadRight(8 ); 
         dwReturn["QTY"] = " ".PadRight(0 ); 
         dwReturn["UNIT"] = " ".PadRight(3 ); 
         dwReturn["CUSTID"] = " ".PadRight(8 ); 
         dwReturn["CUSTOMER"] = " ".PadRight(15 ); 
         dwReturn["JDSTD"] = " ".PadRight(5 ); 
         dwReturn["AQTY"] = " ".PadRight(0 ); 
         dwReturn["RAQTY"] = " ".PadRight(0 ); 
         dwReturn["BQTY"] = " ".PadRight(0 ); 
         dwReturn["CUTQTY"] = " ".PadRight(0 ); 
         dwReturn["SQTY"] = " ".PadRight(0 ); 
         dwReturn["TOTROLL"] = " ".PadRight(0 ); 
         dwReturn["TOTYQTY"] = " ".PadRight(0 ); 
         dwReturn["BROLL"] = " ".PadRight(0 ); 
         dwReturn["BYQTY"] = " ".PadRight(0 ); 
         dwReturn["AVGSCORE"] = " ".PadRight(0 ); 
         dwReturn["MAXSCORE"] = " ".PadRight(0 ); 
         dwReturn["MINSCORE"] = " ".PadRight(0 ); 
         dwReturn["TESROLL"] = " ".PadRight(0 ); 
         dwReturn["TESQTY"] = " ".PadRight(0 ); 
         dwReturn["FISROLL"] = " ".PadRight(0 ); 
         dwReturn["FISQTY"] = " ".PadRight(0 ); 
         dwReturn["TWROLL"] = " ".PadRight(0 ); 
         dwReturn["TWQTY"] = " ".PadRight(0 ); 
         dwReturn["THROLL"] = " ".PadRight(0 ); 
         dwReturn["THQTY"] = " ".PadRight(0 ); 
         dwReturn["OTROLL"] = " ".PadRight(0 ); 
         dwReturn["OTQTY"] = " ".PadRight(0 ); 
         dwReturn["AVWID"] = " ".PadRight(10 ); 
         dwReturn["AVGWID"] = " ".PadRight(0 ); 
         dwReturn["MAXWID"] = " ".PadRight(0 ); 
         dwReturn["MINWID"] = " ".PadRight(0 ); 
         dwReturn["NWIDROLL"] = " ".PadRight(0 ); 
         dwReturn["NWIDQTY"] = " ".PadRight(0 ); 
         dwReturn["CPDAT"] = " ".PadRight(20 ); 
         dwReturn["REMARK"] = " ".PadRight(200 ); 
         dwReturn["NEWUSER"] = " ".PadRight(8 ); 
         dwReturn["NEWTIME"] = " ".PadRight(20 ); 
         dwReturn["CHGUSER"] = " ".PadRight(8 ); 
         dwReturn["CHGTIME"] = " ".PadRight(20 ); 
                    #endregion
                    break;
                case "JLT":

                    break;
                default:

                    break;
            }
            if (IsConvert)
            {
                foreach (DataColumn cm in dwInput.Table.Columns)
                {
                    if (dwInput[cm.ColumnName].ToString() == "")
                        continue;
                    if (dwReturn.Table.Columns.Contains(cm.ColumnName))
                    {
                        dwReturn[cm.ColumnName] = dwInput[cm.ColumnName];
                    }
                }
            }
            return dwReturn;
        }
        public void MapICC_VKQA(ref DataRow dwLocal, DataRow dwData)
        {
            BlindMap(ref dwLocal, dwData);
        }
        public void SaveICC_VKQA(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            DataSet setResult = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            setResult = QueryICC_VKQA(dwData);
            if (setResult.Tables.Count > 0)
            {
                tbLocal = setResult.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }
            MapICC_VKQA(ref dwLocal, dwData);

            if (!flgExist)
            {

                InsertICC_VKQA(dwLocal, ITXDBVERSION);
            }
            UpdateICC_VKQA(dwLocal);
        }
        public void InsertICC_VKQA(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            switch (ITXDBVERSION)
            {
                case "YGR":
                    or1.CommandText = "INSERT INTO ICC_VKQA(VAKBMANDANT, VAKBKOLL, VAKBART, VAKBKUNDNR, VAKBFARBE, VAKBKDARTNR, VAKBKDARTBEZ, VAKBKDFARBNR, VAKBANDRUCK, VAKBMEGEW, VAKBMENGEH, VAKBGEWVON, VAKBGEWBIS, VAKBGEWCA, VAKBGEWFKT, VAKBGEWGRP, VAKBMEGFKT, VAKBMEGGRP, VAKBAENDZL, VAKBAENDBEN, VAKBAENDDAT, VAKBNEUBEN, VAKBNEUDAT, VAKBFILLER)"
                        + " VALUES (:VAKBMANDANT, :VAKBKOLL, :VAKBART, :VAKBKUNDNR, :VAKBFARBE, '                         ', '                         ', '                             ', ' ', '   ', '   ', 0, 0, ' ', '000000000000', ' ', '000000000000', ' ', 0, '        ', '000000', '        ', '      ', '                                          ')";
                    or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                //VAFMANDANT VAFKOLL VAFART VAFFARBE VAFBEZ VAFFFARBE

            }
            
            Connect2Proxy(or1);
        }
        public DataSet QueryICC_VKQA(DataRow dwData, int option = 1)
        {
            DataSet Return;
            DataSet Result = new DataSet();
            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 0:
                    or1.CommandText = "SELECT * FROM ICC_VKQA WHERE  ROWNUM<2 ";
                    break;
              
                case 99:
                    or1.CommandText = "SELECT * FROM ICC_VKQA  WHERE ROWNUM<50";
                    break;
                default:
                    break;
            }
            Result = Connect2Proxy(or1);
            if (Result.Tables.Count > 0)
                Result.Tables[0].TableName = "ICC_VKQA";
            Return = Result;
            return Return;
        }

        public DataSet QVKA1(DataRow dwData)
        {
            or1 = OracleDB.CreateCommand();
            or1.CommandText = "SELECT * FROM ICC_VKQA WHERE ROWNID = :ROWNID: AND MANDANT = :MANDANT:";
            or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
            SResult = Connect2Proxy(or1);
            SResult.Tables[0].TableName = TableName;
            return SResult;
        }

        public void DeleteICC_VKQA(DataRow dwData, int option = 1)
        {

            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    or1.CommandText = "DELETE FROM ICC_VKQA   WHERE  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                     or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                default:
                    break;
            }
            Connect2Proxy(or1);
        } 
       
        public void UpdateICC_VKQA(DataRow dwData, string ITXDBVERSION = "50.24", int option = 1)
        {
            OracleCommand or1;
            DataSet Result = new DataSet();
            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    #region====Command==== 
                    or1.CommandText = "UPDATE ICC_VKQA SET "
                    +"ROWNID= :ROWNID,"
                    +"MANDANT= :MANDANT,"
                    +"COLL= :COLL,"
                    +"ART= :ART,"
                    +"CONS= :CONS,"
                    +"COLOR= :COLOR,"
                    +"WID= :WID,"
                    +"STAFF= :STAFF,"
                    +"QTY= :QTY,"
                    +"UNIT= :UNIT,"
                    +"CUSTID= :CUSTID,"
                    +"CUSTOMER= :CUSTOMER,"
                    +"JDSTD= :JDSTD,"
                    +"AQTY= :AQTY,"
                    +"RAQTY= :RAQTY,"
                    +"BQTY= :BQTY,"
                    +"CUTQTY= :CUTQTY,"
                    +"SQTY= :SQTY,"
                    +"TOTROLL= :TOTROLL,"
                    +"TOTYQTY= :TOTYQTY,"
                    +"BROLL= :BROLL,"
                    +"BYQTY= :BYQTY,"
                    +"AVGSCORE= :AVGSCORE,"
                    +"MAXSCORE= :MAXSCORE,"
                    +"MINSCORE= :MINSCORE,"
                    +"TESROLL= :TESROLL,"
                    +"TESQTY= :TESQTY,"
                    +"FISROLL= :FISROLL,"
                    +"FISQTY= :FISQTY,"
                    +"TWROLL= :TWROLL,"
                    +"TWQTY= :TWQTY,"
                    +"THROLL= :THROLL,"
                    +"THQTY= :THQTY,"
                    +"OTROLL= :OTROLL,"
                    +"OTQTY= :OTQTY,"
                    +"AVWID= :AVWID,"
                    +"AVGWID= :AVGWID,"
                    +"MAXWID= :MAXWID,"
                    +"MINWID= :MINWID,"
                    +"NWIDROLL= :NWIDROLL,"
                    +"NWIDQTY= :NWIDQTY,"
                    +"CPDAT= :CPDAT,"
                    +"REMARK= :REMARK,"
                    +"NEWUSER= :NEWUSER,"
                    +"NEWTIME= :NEWTIME,"
                    +"CHGUSER= :CHGUSER,"
                    +"CHGTIME= :CHGTIME,"
                        + " WHERE  "
                        + "  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                    #endregion

                    #region====Parameters====
          or1.Parameters.Add("ROWNID", OracleType.NVarChar).Value = dwData["ROWNID"].ToString(); 
          or1.Parameters.Add("MANDANT", OracleType.NVarChar).Value = dwData["MANDANT"].ToString(); 
          or1.Parameters.Add("COLL", OracleType.NVarChar).Value = dwData["COLL"].ToString(); 
          or1.Parameters.Add("ART", OracleType.NVarChar).Value = dwData["ART"].ToString(); 
          or1.Parameters.Add("CONS", OracleType.NVarChar).Value = dwData["CONS"].ToString(); 
          or1.Parameters.Add("COLOR", OracleType.NVarChar).Value = dwData["COLOR"].ToString(); 
          or1.Parameters.Add("WID", OracleType.NVarChar).Value = dwData["WID"].ToString(); 
          or1.Parameters.Add("STAFF", OracleType.NVarChar).Value = dwData["STAFF"].ToString(); 
          or1.Parameters.Add("QTY", OracleType.NVarChar).Value = dwData["QTY"].ToString(); 
          or1.Parameters.Add("UNIT", OracleType.NVarChar).Value = dwData["UNIT"].ToString(); 
          or1.Parameters.Add("CUSTID", OracleType.NVarChar).Value = dwData["CUSTID"].ToString(); 
          or1.Parameters.Add("CUSTOMER", OracleType.NVarChar).Value = dwData["CUSTOMER"].ToString(); 
          or1.Parameters.Add("JDSTD", OracleType.NVarChar).Value = dwData["JDSTD"].ToString(); 
          or1.Parameters.Add("AQTY", OracleType.NVarChar).Value = dwData["AQTY"].ToString(); 
          or1.Parameters.Add("RAQTY", OracleType.NVarChar).Value = dwData["RAQTY"].ToString(); 
          or1.Parameters.Add("BQTY", OracleType.NVarChar).Value = dwData["BQTY"].ToString(); 
          or1.Parameters.Add("CUTQTY", OracleType.NVarChar).Value = dwData["CUTQTY"].ToString(); 
          or1.Parameters.Add("SQTY", OracleType.NVarChar).Value = dwData["SQTY"].ToString(); 
          or1.Parameters.Add("TOTROLL", OracleType.NVarChar).Value = dwData["TOTROLL"].ToString(); 
          or1.Parameters.Add("TOTYQTY", OracleType.NVarChar).Value = dwData["TOTYQTY"].ToString(); 
          or1.Parameters.Add("BROLL", OracleType.NVarChar).Value = dwData["BROLL"].ToString(); 
          or1.Parameters.Add("BYQTY", OracleType.NVarChar).Value = dwData["BYQTY"].ToString(); 
          or1.Parameters.Add("AVGSCORE", OracleType.NVarChar).Value = dwData["AVGSCORE"].ToString(); 
          or1.Parameters.Add("MAXSCORE", OracleType.NVarChar).Value = dwData["MAXSCORE"].ToString(); 
          or1.Parameters.Add("MINSCORE", OracleType.NVarChar).Value = dwData["MINSCORE"].ToString(); 
          or1.Parameters.Add("TESROLL", OracleType.NVarChar).Value = dwData["TESROLL"].ToString(); 
          or1.Parameters.Add("TESQTY", OracleType.NVarChar).Value = dwData["TESQTY"].ToString(); 
          or1.Parameters.Add("FISROLL", OracleType.NVarChar).Value = dwData["FISROLL"].ToString(); 
          or1.Parameters.Add("FISQTY", OracleType.NVarChar).Value = dwData["FISQTY"].ToString(); 
          or1.Parameters.Add("TWROLL", OracleType.NVarChar).Value = dwData["TWROLL"].ToString(); 
          or1.Parameters.Add("TWQTY", OracleType.NVarChar).Value = dwData["TWQTY"].ToString(); 
          or1.Parameters.Add("THROLL", OracleType.NVarChar).Value = dwData["THROLL"].ToString(); 
          or1.Parameters.Add("THQTY", OracleType.NVarChar).Value = dwData["THQTY"].ToString(); 
          or1.Parameters.Add("OTROLL", OracleType.NVarChar).Value = dwData["OTROLL"].ToString(); 
          or1.Parameters.Add("OTQTY", OracleType.NVarChar).Value = dwData["OTQTY"].ToString(); 
          or1.Parameters.Add("AVWID", OracleType.NVarChar).Value = dwData["AVWID"].ToString(); 
          or1.Parameters.Add("AVGWID", OracleType.NVarChar).Value = dwData["AVGWID"].ToString(); 
          or1.Parameters.Add("MAXWID", OracleType.NVarChar).Value = dwData["MAXWID"].ToString(); 
          or1.Parameters.Add("MINWID", OracleType.NVarChar).Value = dwData["MINWID"].ToString(); 
          or1.Parameters.Add("NWIDROLL", OracleType.NVarChar).Value = dwData["NWIDROLL"].ToString(); 
          or1.Parameters.Add("NWIDQTY", OracleType.NVarChar).Value = dwData["NWIDQTY"].ToString(); 
          or1.Parameters.Add("CPDAT", OracleType.NVarChar).Value = dwData["CPDAT"].ToString(); 
          or1.Parameters.Add("REMARK", OracleType.NVarChar).Value = dwData["REMARK"].ToString(); 
          or1.Parameters.Add("NEWUSER", OracleType.NVarChar).Value = dwData["NEWUSER"].ToString(); 
          or1.Parameters.Add("NEWTIME", OracleType.NVarChar).Value = dwData["NEWTIME"].ToString(); 
          or1.Parameters.Add("CHGUSER", OracleType.NVarChar).Value = dwData["CHGUSER"].ToString(); 
          or1.Parameters.Add("CHGTIME", OracleType.NVarChar).Value = dwData["CHGTIME"].ToString(); 
                    #endregion
                    break; 
                default:
                    break;
            }


            Connect2Proxy(or1);
        }
    }
}
